import router from '@/router'
import { defineStore } from 'pinia'
import { ref, watch, type Ref } from 'vue'

export const useMainStore = defineStore(
  'main',
  () => {
    const activeIndex: Ref<string> = ref('')
    watch(
      activeIndex,
      (value) => {
        // console.log(value)
        if (value.length === 0) return
        router.push(value)
      },
      { deep: true },
    )
    return { activeIndex }
  },
  {
    persist: {
      storage: sessionStorage,
      key: 'main',
    },
  },
)
